class Solution {
public:
    void dfs(vector<int>& nums, vector<bool>& vis, vector<int>&& num,
             vector<vector<int>>& ans) {
        if (num.size() == nums.size()) {
            ans.push_back(num);
            return;
        }
        for (int i = 0; i < nums.size(); i++) {
            if (vis[nums[i] + 10] == false) {
                vis[nums[i] + 10] = true;
                num.push_back(nums[i]);
                dfs(nums, vis, move(num), ans);
                vis[nums[i] + 10] = false;
                num.pop_back();
            }
        }
    }
    vector<vector<int>> permute(vector<int>& nums) {
        vector<vector<int>> ans;
        vector<bool> vis(30, false);
        dfs(nums, vis, vector<int>(), ans);
        return ans;
    }
};